package day5.Exer;


import java.util.*;

public class Company  {
    private String name;
    private String adress;
    private String telephone;
    private String scope;
    Map<String, Staff> st = new HashMap<>();

    public Company() {
    }

    public Company(String name, String adress, String telephone, String scope) {
        this.name = name;
        this.adress = adress;
        this.telephone = telephone;
        this.scope = scope;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    //添加新员工
    public void add(String no,Staff b) {
        if(st.containsValue(b)){
            System.out.println("员工已存在");
        }else {
            st.put(b.getStNo(), b);
            System.out.println("添加成功");
        }
    }

    //员工总人数
    public void showsum() {
        System.out.println("公司共有" + st.size() + "名员工");
    }

    //显示员工信息
    public void showinfo() {
        Set<Map.Entry<String,Staff>> set=st.entrySet();
        Iterator<Map.Entry<String,Staff>> ir=set.iterator();
        while (ir.hasNext()) {
            Map.Entry<String, Staff> next =  ir.next();
            System.out.println("工号"+next.getKey()+"姓名：" + next.getValue().getName() + "；性别：" + next.getValue().getSex() + "；年龄：" + next.getValue().getAge() + ";职位：" + next.getValue().getJob() + ";薪水：" + next.getValue().getSalary());
        }

    }

    //开除员工
    public boolean dismiss(String disname) {
        if (st.isEmpty()) {
            System.out.println("公司没有员工");
        } else {
            Set<Map.Entry<String,Staff>> set=st.entrySet();
            Iterator<Map.Entry<String,Staff>> ir=set.iterator();
            while (ir.hasNext()) {
                Map.Entry<String, Staff> next =  ir.next();
                if((next.getValue().getName()).equals(disname)){
                    st.remove(next.getKey());
                    System.out.println(disname+"已被开除");
                }
            }if(!(ir.hasNext())){
                System.out.println("公司无该员工");
            }
        }

        return true;
    }

    public void findTopSalary() {
        List a= Arrays.asList(st.values().toArray());
       Staff max=(Staff)Collections.max(a);
        System.out.println("工资最高的员工是"+max.getName());
    }

}
